package com.qfedu.dtboot.controller;

import com.qfedu.dtboot.entity.ScheduleJob;
import com.qfedu.dtboot.service.ScheduleJobService;
import com.qfedu.dtboot.util.DataGridResult;
import com.qfedu.dtboot.util.Query;
import com.qfedu.dtboot.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

/**
 * 定时任务(ScheduleJob)表控制层
 *
 * @author ykx
 * @since 2022-09-27 13:04:17
 */
@RestController
@RequestMapping("schedule/job")
public class ScheduleJobController {
    /**
     * 服务对象
     */
    @Resource
    private ScheduleJobService scheduleJobService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ScheduleJob selectOne(Long id) {
        return null;
    }

    @GetMapping("/list")
    public DataGridResult getJobList(@RequestParam Map<String, Object> params){
        Query query = new Query(params);
        return scheduleJobService.queryJobList(query);
    }

    @PostMapping("save")
    public R save(@RequestBody ScheduleJob scheduleJob){
        System.out.println("scheduleJob = " + scheduleJob);
        return scheduleJobService.saveJob(scheduleJob);
    }

    @PostMapping("update")
    public R update(@RequestBody ScheduleJob scheduleJob){
        System.out.println(scheduleJob);
        return scheduleJobService.updateJob(scheduleJob);
    }

    @GetMapping("info/{jobId}")
    public R getJobInfo(@PathVariable Long jobId){
        return scheduleJobService.getJobInfoById(jobId);
    }

    @PostMapping("del")
    public R delJob(@RequestBody Long[] ids){
        System.out.println(Arrays.toString(ids));
        return scheduleJobService.delBatchJobs(ids);
    }

    @PostMapping("pause")
    public R pauseJob(@RequestBody Long[] ids){
        return scheduleJobService.pauseJobs(ids);
    }

    @PostMapping("resume")
    public R resumeJob(@RequestBody Long[] ids){
        return scheduleJobService.resumeJobs(ids);
    }

}
